package com.alibaba.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Author: zhuangzhiwen
 * @Date: 2021/8/18
 */
@Component
@Aspect
public class AopAnnotation {

    @Pointcut("execution(* com.alibaba.service..*.*(..))")
    public void pc() {

    }

    @Before("pc()")
    public void before() {
        System.out.println("before。。。。。。。");
    }

    @Around("pc()")
    public void around(ProceedingJoinPoint joinPoint) {
        try {
            Object result = joinPoint.proceed(joinPoint.getArgs());
            System.out.println("before.....");
            System.out.println("after-return.....");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("ex.....");
        } finally {
            System.out.println("after.....");
        }
    }
}
